package com.buer.storage.api;


import com.buer.storage.business.dto.AorderDto;
import com.buer.storage.business.dto.AorderSelectDto;
import com.buer.storage.business.dto.AorderStorageDto;
import com.buer.storage.business.service.AorderService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.utils.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/Aorder")
public class AorderController {
    @Resource
    private AorderService aorderService;

    //增加入库信息
    @Auth
    @PostMapping("/insertAorderStorage.do")
    public BaseResult insert(@RequestBody AorderStorageDto aorderStorageDto){
        //System.out.println(aorderStorageDto);
        if (aorderService.insert(aorderStorageDto) > 0) {

            return BaseResult.build(ResultEnum.SUCCESS);
        }
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //根据订单ID查询入库信息
    @Auth
    @GetMapping("/findAorderAllById.do")
    public BaseResult findPutAll(Integer allotId){
        List<AorderSelectDto> aorderAllById = aorderService.findAorderAllById(allotId);
        return BaseResult.build(ResultEnum.SUCCESS,aorderAllById);
    }

    //查询所有订单信息
    @GetMapping("/findAorder.do")
    @Auth
    public BaseResult findAorder(){
        List<AorderDto> aorderAll = aorderService.findAorder();
        return BaseResult.build(ResultEnum.SUCCESS,aorderAll);
    }

    //根据入库订单ID删除入库信息
    @GetMapping("/deleteAorderById.do")
    @Auth
    public BaseResult deleteAorderById(Integer allotId) {
        if (aorderService.deleteAorderById(allotId) > 0) {
            //删除调拨单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //删除调拨单失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //更新ID删除商品信息
    @Auth
    @PostMapping("/updateAorderdetails.do")
    public BaseResult updateAorderdetails(@RequestBody AorderStorageDto aorderStorageDto) {
        if (aorderService.updateAorderdetails(aorderStorageDto) > 0) {
            //更新调拨单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //更新调拨单失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //提交商品详情进行累加
    @Auth
    @GetMapping("/submitAddBuerStock.do")
    public BaseResult submitAddBuerStock(Integer allotId) {
        if (aorderService.submitAddBuerStock(allotId) > 0) {
            //调拨成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //调拨失败
        return BaseResult.build(ResultEnum.FAILURE);
    }
}
